package org.anq.ddm.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.anq.ddm.mapper.BpmnProcessMapper;
import org.anq.ddm.pojo.BpmnProcess;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BpmnProcessService extends ServiceImpl<BpmnProcessMapper, BpmnProcess> {

    @Autowired
    BpmnProcessMapper porcessInfoMapper;

    public BpmnProcess findByProcessKey(String processkey) {
        QueryWrapper<BpmnProcess> qw = new QueryWrapper();
        if (processkey != null) {
            qw.eq("processkey", processkey);
        }
        BpmnProcess d = this.porcessInfoMapper.selectOne(qw);
        return d;
    }

    public List<BpmnProcess> findByStatus(Integer status) {
        QueryWrapper<BpmnProcess> qw = new QueryWrapper();
        if (status != null) {
            qw.eq("status", status);
        }
        List<BpmnProcess> d = this.porcessInfoMapper.selectList(qw);
        return d;
    }

    public Integer updateProcess(Integer processId,String formKey){
        UpdateWrapper<BpmnProcess> uw = new UpdateWrapper<>();
        if(processId!=null){
            uw.eq("id",processId);
            BpmnProcess bp = new BpmnProcess();
            bp.setFormid(formKey);
            return this.porcessInfoMapper.update(bp,uw);
        }else{
            return 0;
        }
    }
}
